package me.xuym.crawler.house58statistics;

import com.cbs.java.component.application.Application;
import com.cbs.java.component.database.Database;
import com.cbs.java.component.database.mysql.MySqlDatabase;
import me.xuym.crawler.Dispatcher;
import net.duguying.pinyin.Pinyin;

import java.util.List;

/**
 * Created by broche on 10/09/2017.
 */
public class House58DeltaAddressDispatcher extends Dispatcher<List<House58DeltaAddress>> {
    private Database database;

    public House58DeltaAddressDispatcher(Application application) throws Exception {
        super(application);
        database = new MySqlDatabase("home.xuym.me", "3306", "root", "Tomato.14210", "crawler");
    }

    @Override
    protected void onDispatch(List<House58DeltaAddress> addresses) throws Exception {
        Pinyin pinyin = new Pinyin();
        for (House58DeltaAddress address : addresses) {
            String py = pinyin.translateFirstChar(address.getAddress());
            database.insert(String.format("insert into house58address(address, addressfinal, py, sort) values (\"%s\", \"%s\", \"%s\", 0)", address.getAddress(), address.getAddress(), py));
        }
    }
}
